import Axios from 'axios'

const xhr = Axios.create({
	timeout: 6000
})


export const API = {
	get (url, params, conf = {}) {
		return new Promise(async (resolve, reject) => {
			try {
				const res = await xhr.get(url, { params, ...conf })
				res.data.code === 10000 || res.data.returncode * 1 === 10000 ? resolve(res.data) : reject(res.data.message)
			} catch (err) {
				reject(err)
			}
		})
	},
	post (url, params, conf = {}) {
		return new Promise(async (resolve, reject) => {
			try {
				const res = await xhr.post(url, params, conf)
				res.data.code === 10000 || res.data.returncode * 1 === 10000 ? resolve(res.data) : reject(res.data.message)
			} catch (err) {
				reject(err)
			}
		})
	}
}